//
//  HookWebViewController.m
//  Staff
//
//  Created by caiyao on 1/6/15.
//
//

#import "HookWebViewController.h"
#import "HTTPUtil.h"
#import "RequestChecker.h"
#import "hookDispatcher.h"
#import "NSData-AES.h"

#import <AudioToolbox/AudioToolbox.h>

#define longPressTime 3

#define startPage @"file:///web/prelogon/logon/logon.html"

@interface HookWebViewController ()

@end

@implementation HookWebViewController

SystemSoundID theSoundID;

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    // Do any additional setup after loading the view from its nib.
//    _webContentView = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+20, self.view.frame.size.width, self.view.frame.size.height-20)];
        _webContentView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    _webContentView.backgroundColor = [UIColor clearColor];
    _webContentView.opaque = YES;
    _webContentView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _webContentView.delegate = self;
    [self.view addSubview:_webContentView];
    
    _webContentViewR = [[UIWebView alloc] initWithFrame:_webContentView.bounds];
    _webContentViewR.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _webContentViewR.backgroundColor = [UIColor clearColor];
    _webContentViewR.opaque = YES;
    _webContentViewR.delegate = self;
    _webContentViewR.hidden = YES;
    [self.view addSubview:_webContentViewR];
    
    _webContentViewL = [[UIWebView alloc] initWithFrame:_webContentView.bounds];
    _webContentViewL.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _webContentViewL.delegate = self;
    _webContentViewL.backgroundColor = [UIColor clearColor];
    _webContentViewL.opaque = YES;
    _webContentViewL.hidden = YES;
    [self.view addSubview:_webContentViewL];
    
    _webContentView.allowsInlineMediaPlayback=YES;
    _webContentView.mediaPlaybackRequiresUserAction=NO;
    _webContentViewL.allowsInlineMediaPlayback=YES;
    _webContentViewL.mediaPlaybackRequiresUserAction=NO;
    _webContentViewR.allowsInlineMediaPlayback=YES;
    _webContentViewR.mediaPlaybackRequiresUserAction=NO;
    
    _hookDispatcher = [[HookDispatcher alloc] init];
    [self resetView];
    [self setBlankDoc];
    
    homeUUID = [[self getHomePathUUID] retain];
    [self setupSwipeGestures];
    [self loadStartupPage];
    
}

- (void)setBlankDoc
{
    [_webContentView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];
}

-(void)resetView
{
    //cancel any previous loads
    if ([_webContentView isLoading])
    {
        DebugLog(@"webContentView loading");
        //DebugLog(@"RefreshView: page still loading - abort it");
        [_webContentView stopLoading];
    }
    
    DebugLog(@"resetView");
    //clear webview so that we dont see previous country's page if load fails
    //[webContentView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];
    
//    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TransparentWebViewController" ofType:@"html"];
//    
//    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
//    if (htmlString)
//    {
//        _webContentView.backgroundColor = [UIColor clearColor];
//        [_webContentView loadHTMLString:htmlString baseURL:nil];
//    }
    
    //cancel any previous loads
    if ([_webContentView isLoading]) {
        DebugLog(@"webContentView loading");
        //DebugLog(@"RefreshView: page still loading - abort it");
        [_webContentView stopLoading];
    }
}

- (void)openMyLaisee {
    NSString *targetURL = [self handlingOpenURL:@"file:///web/postlogon/myLaisee/myLaiSee.html"];

    [self loadUrl:targetURL handlingWebView:_webContentView];
}

- (void)loadStartupPage {
    
    NSString *startpageURL = startPage;
    
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    
    NSData *data = [defs objectForKey:@"customerInfo"];
    NSData *encryptedData = [NSData dataWithData:data];
    NSData *saveData = [encryptedData AES256DecryptWithKey:secureToken];
    NSString *value = [[NSString alloc] initWithData:saveData encoding:NSUTF8StringEncoding];
    
    if (nil!=value&&![@"" isEqualToString:value]) {
        startpageURL=@"file:///web/postlogon/menu/menu.html";
        
        //startpageURL=@"file://web/postlogon/myLaisee/myLaiSee.html";
        
    } 
    NSString *targetURL = [self handlingOpenURL:startpageURL];
    if (targetURL) {
         [self loadUrl:targetURL handlingWebView:_webContentView];
    }
   
}

- (void) setupSwipeGestures
{
    // setup swipe gestures, with config definition.
    
    if (self.oneFingerSwipeLeft == nil)
    {
        self.oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(oneFingerSwipeLeftHandler:)] autorelease];
        [self.oneFingerSwipeLeft setNumberOfTouchesRequired:1];
        
        [self.oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
        
        self.oneFingerSwipeLeft.delegate = self;
    }
    
    if (self.oneFingerSwipeRight == nil)
    {
        self.oneFingerSwipeRight = [[[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                              action:@selector(oneFingerSwipeRightHandler:)]autorelease];
        [self.oneFingerSwipeRight setNumberOfTouchesRequired:1];
        
        [self.oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
        
        self.oneFingerSwipeRight.delegate = self;
    }
    
    if (self.oneFingerSwipeUp == nil)
    {
        self.oneFingerSwipeUp = [[[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                           action:@selector(oneFingerSwipeUpHandler:)]autorelease];
        [self.oneFingerSwipeUp setNumberOfTouchesRequired:1];
        
        [self.oneFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
        
        self.oneFingerSwipeUp.delegate = self;
    }
    
    if (self.oneFingerSwipeDown == nil)
    {
        self.oneFingerSwipeDown = [[[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(oneFingerSwipeDownHandler:)]autorelease];
        
        [self.oneFingerSwipeDown setNumberOfTouchesRequired:1];
        
        [self.oneFingerSwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
        
        self.oneFingerSwipeDown.delegate = self;
    }
    
    if (self.longPress == nil)
    {
        self.longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self
                                                                        action:@selector(longPressHandler:)]autorelease];
        [self.longPress setNumberOfTouchesRequired:1];
        [self.longPress setMinimumPressDuration:0.3]; // set 3 sec
        self.longPress.delegate = self;
    }
    
    // reset swipe gesture for sso case and switch web module case.
    
    [self.oneFingerSwipeLeft.view removeGestureRecognizer:self.oneFingerSwipeLeft];
    [self.oneFingerSwipeRight.view removeGestureRecognizer:self.oneFingerSwipeRight];
    [self.oneFingerSwipeUp.view removeGestureRecognizer:self.oneFingerSwipeUp];
    [self.oneFingerSwipeDown.view removeGestureRecognizer:self.oneFingerSwipeDown];
    
    [self.longPress.view removeGestureRecognizer:self.longPress];
}

- (void)registerLongPress:(NSString *)eventJS {
    self.longPressEnventJs = eventJS;
    // add longPress gestures
    [[self view] removeGestureRecognizer:self.longPress];
    [[self view] addGestureRecognizer:self.longPress];

}

- (void)unRegisterLongPress {
    [self.longPress.view removeGestureRecognizer:self.longPress];
}

// Swipe left handler.
-(void) oneFingerSwipeLeftHandler:(UITapGestureRecognizer *)recognizer
{
    DebugLog(@"oneFingerSwipeLeftHandler");
    
    NSString *jsCall = [NSString stringWithFormat:@"%@('%@');",self.gestureEnventJs,@"Left",nil];
    
    NSString *jsResponse = [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    
    DebugLog(@"jsResponse:%@",jsResponse);
}

// Swipe right handler.
-(void) oneFingerSwipeRightHandler:(UITapGestureRecognizer *)recognizer
{
    DebugLog(@"oneFingerSwipeRightHandler");
    
    NSString *jsCall = [NSString stringWithFormat:@"%@('%@');",self.gestureEnventJs,@"Right",nil];
    
    NSString *jsResponse = [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    
    DebugLog(@"jsResponse:%@",jsResponse);
}

// Swipe up handler.
-(void) oneFingerSwipeUpHandler:(UITapGestureRecognizer *)recognizer
{
    DebugLog(@"oneFingerSwipeUpHandler");
    
    NSString *jsCall = [NSString stringWithFormat:@"%@('%@');",self.gestureEnventJs,@"Up",nil];
    
    NSString *jsResponse = [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    
    DebugLog(@"jsResponse:%@",jsResponse);
}

// Swipe down handler.
-(void) oneFingerSwipeDownHandler:(UITapGestureRecognizer *)recognizer
{
    DebugLog(@"oneFingerSwipeDownHandler");
    
    NSString *jsCall = [NSString stringWithFormat:@"%@('%@');",self.gestureEnventJs,@"Down",nil];
    
    NSString *jsResponse = [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    
    DebugLog(@"jsResponse:%@",jsResponse);
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UIButton class]]) {
        return NO; // ignore the touch
    }
    return YES; // handle the touch
}


// long press handler.
-(void) longPressHandler:(UITapGestureRecognizer *)recognizer
{
    // UIGestureRecognizerState *state=[recognizer state];
    if ([recognizer state] == UIGestureRecognizerStateBegan) {
        //        [CircleDownCounter showCircleDownWithSeconds:3.0f onView:self.webContentView
        //                                            withSize:CGSizeMake(188, 188)
        //                                             andType:CircleDownCounterTypeIntegerDecre];
        
        
        CGPoint touchPoint = [recognizer locationInView:_webContentView];
        int y=touchPoint.y;
        int x=touchPoint.x;
        if (y>100 &&x>50 &&x<320-50&&y<self.view.bounds.size.height-50 ) {
            
            
            self.counterView =[[KKProgressTimer alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-100, self.view.frame.size.height/2-100, 180, 180)];
            
            self.counterView.backgroundColor=[UIColor clearColor];
            self.counterView.delegate=self;
            [self.view addSubview:self.counterView];
            __block CGFloat i1 = 0;
            [self.counterView startWithBlock:^CGFloat {
                return i1++ / 60;
            }];
            self.longPressTimer=[[[NSTimer alloc] init]retain];
            self.longPressSecond=0;
            self.longPressTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0f)
                                                                   target:self
                                                                 selector:@selector(updateLongPressSecond)
                                                                 userInfo:nil
                                                                  repeats:YES];
            
            
            SystemSoundID soundID;
            
            NSString *name = @"unlock";
            
            NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
            AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
            theSoundID=soundID;
            AudioServicesPlaySystemSound(soundID);
        }
        NSLog(@"LongGesture Start");
        
    }
    
    else if ([recognizer state] == UIGestureRecognizerStateEnded)
        
    {
        if (self.longPressSecond<longPressTime-1) {
            
            
            //             [CircleDownCounter removeCircleViewFromView:self.webContentView];
        }
        else
        {
            [self longPressCallBack];
        }
        [self.longPressTimer invalidate];
        self.longPressTimer=nil;
        [self.longPressTimer release];
        [self.counterView removeFromSuperview];
        AudioServicesDisposeSystemSoundID(theSoundID);
        
        NSLog(@"LongGesture End");
        NSLog(@"LongGesture UIGestureRecognizerStateCancelled");
        
        
        
        
    }
    else if ([recognizer state] == UIGestureRecognizerStateCancelled)
        
    {
        AudioServicesDisposeSystemSoundID(theSoundID);
        [self.counterView removeFromSuperview];
        [self.longPressTimer invalidate];
        self.longPressTimer=nil;
        [self.longPressTimer release];
    }
    else if ([recognizer state] == UIGestureRecognizerStateFailed)
        
    {
        
        NSLog(@"LongGesture UIGestureRecognizerStateFailed");
        
    }
    else if ([recognizer state] == UIGestureRecognizerStateChanged)
        
    {
        
        NSLog(@"LongGesture UIGestureRecognizerStateChanged");
        
    }
    else if ([recognizer state] == UIGestureRecognizerStatePossible)
        
    {
        
        NSLog(@"LongGesture UIGestureRecognizerStatePossible");
        
    }
    
    
    
    DebugLog(@"longPressHandler");
    //    DebugLog(@"start show loading view");
    
    //    [self showLoadingView];
    //    NSTimer *longPressTimer = [[NSTimer timerWithTimeInterval:1 target:self selector:@selector(changeUI) userInfo:nil repeats:YES];
    //    longPressTimer
}

-(void)updateLongPressSecond
{
    DebugLog(@"updateLongPressSecond");
    if (self.longPressSecond <longPressTime-1) {
        DebugLog(@"longPressSecond : %d",self.longPressSecond);
        self.longPressSecond++;
        self.counterView.secondImageView.image=[UIImage imageNamed:[NSString stringWithFormat: @"countdown-%d.png",longPressTime-self.longPressSecond]];
    }
    else if (self.longPressSecond ==longPressTime-1){
        [self longPressCallBack];
        [self.longPressTimer invalidate];
        self.longPressTimer=nil;
        [self.longPressTimer release];
        AudioServicesDisposeSystemSoundID(theSoundID);
        [self.counterView removeFromSuperview];
        self.longPressSecond=0;
        
    }
    else{  [self.longPressTimer invalidate];
        self.longPressTimer=nil;
        [self.longPressTimer release];
        AudioServicesDisposeSystemSoundID(theSoundID);
        [self.counterView removeFromSuperview];
        self.longPressSecond=0;
    }
}

-(void)longPressCallBack
{
    NSString *jsCall = [NSString stringWithFormat:@"%@('');",self.longPressEnventJs];
    
    NSString *jsResponse = [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    DebugLog(@"jsResponse:%@",jsResponse);
    
    
}

- (void)pageTransaction:(NSString *)targetLink slide:(NSString *)slide {
    isPageTransactioning = YES;
    
    _webContentViewL.delegate =nil;
    _webContentViewR.delegate =nil;
    //UIWebView *targetWebView;
    
    if (_webContentView == _webContentViewL)
    {
        //targetWebView = self.webContentViewR;
        _webContentViewR.delegate =self;
        _webContentView = _webContentViewR;
    }
    else
    {
        //targetWebView = self.webContentViewL;
        _webContentViewL.delegate =self;
        _webContentView = _webContentViewL;
    }
    self.pageSlide = slide;
    
    [self loadUrl:targetLink handlingWebView:_webContentView];
}

- (void) handlePageTransaction
{
    UIWebView *sourceWebView;
    UIWebView *targetWebView;
    
    if (_webContentView == _webContentViewL)
    {
        sourceWebView = _webContentViewR;
        targetWebView = _webContentViewL;
    }
    else
    {
        sourceWebView = _webContentViewL;
        targetWebView = _webContentViewR;
    }
    
    // create a CATransition object to describe the transition
    CATransition *transition = [CATransition animation];
    // Animate over 1/4 of a second
    transition.duration = 0.25;
    //  using the ease in/out timing function
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    
    //**** type = kCATransitionMoveIn,kCATransitionPush,kCATransitionReveal
    //**** subtype = kCATransitionFromLeft,kCATransitionFromRight,kCATransitionFromTop,kCATransitionFromBottom
    //**** type = kCATransitionFade
    
    transition.type = kCATransitionPush;
    if (self.pageSlide == nil)
    {
        transition.subtype = kCATransitionFromLeft;
    }
    else if ([[self.pageSlide uppercaseString]isEqualToString:@"LTR"])
    {
        transition.subtype = kCATransitionFromLeft;
    }
    else if ([[self.pageSlide uppercaseString]isEqualToString:@"RTL"])
    {
        transition.subtype = kCATransitionFromRight;
    }
    else
    {
        transition.subtype = kCATransitionFromLeft;
    }
    
    transition.delegate = self;
    
    [targetWebView setHidden:NO];
    [sourceWebView setHidden:YES];
    
    [self.view.layer addAnimation:transition forKey:nil];
    
    isPageTransactioning = NO;
    
    _webContentView.frame = CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-20);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    //log url requested
    BOOL continueLoad = TRUE;
    
    NSURL *reqURL = [request URL];
    NSString *urlString = [reqURL absoluteString];
    
    if ([urlString isEqualToString:@"about:blank"])
    {
        return NO;
    }
    
//    // handle file:
//    if ([reqURL isFileURL])
//    {
//        NSString *openurlString =[self handlingOpenURL:urlString];
//        
//        if (openurlString !=nil)
//        {
//            [self loadUrl:openurlString handlingWebView:webView];
//        }
//        
//        return FALSE;
//    }
    
    if ([RequestChecker hasAppScheme:request]) {
        DebugLog(@"Request to invoke a builtin app");
        if ([[UIApplication sharedApplication]canOpenURL:reqURL]) {
            DebugLog(@"Request can be handled");
            [[UIApplication sharedApplication]openURL:reqURL];
        }
        else
        {
            DebugLog(@"Request can't be handled");
        }
        DebugLog(@"Stopping load");
        [webView stopLoading];
        continueLoad = FALSE;
    }
    else {
        if ([RequestChecker hasCustomScheme:request]) {
            [_hookDispatcher dispatchRequest:request webView:webView hookWebViewController:self];
            continueLoad = FALSE;
        }
        else {
            continueLoad = TRUE;
        }
    }
    
    if (continueLoad)
    {
        // set allow ssl certificate
        [HTTPUtil setAllowsSSLCertificate:request url:[request URL]];
    }
    
    return continueLoad;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    if (isPageTransactioning)
    {
        [self handlePageTransaction];
    }
    //TODO
    //[self hideProgress];
    [_webContentView stringByEvaluatingJavaScriptFromString: @"document.documentElement.style.webkitUserSelect='none';"];
    [_webContentViewL stringByEvaluatingJavaScriptFromString: @"document.documentElement.style.webkitUserSelect='none';"];
    [_webContentViewR stringByEvaluatingJavaScriptFromString: @"document.documentElement.style.webkitUserSelect='none';"];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    NSLog(@"failed load with error %@",error);
}

- (void) loadUrl:(NSString *)requestLink handlingWebView:(UIWebView *)handlingWebView
{
    NSURL *url =[NSURL URLWithString:requestLink];
    
    DebugLog(@"url is %@",[url absoluteString]);
    NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url
                                                            cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                        timeoutInterval:20.0];//[mainBundle bundleIdentifier]
    handlingWebView.scrollView.scrollEnabled = NO;
    [handlingWebView loadRequest:urlRequest];
}

static   NSString *uuidRegexMatchPattern = @"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";


- (NSString *) getHomePathUUID
{
    NSError *regecError = NULL;
    
    NSString *regexPattern = uuidRegexMatchPattern;
    
    NSRegularExpression *uuidRegex = [NSRegularExpression regularExpressionWithPattern:regexPattern
                                                                               options:0
                                                                                 error:&regecError];
    NSString *homePath = NSHomeDirectory();
    DebugLog(@"getHomeUUID is %@",homePath);
    
    NSRange homeUUIDPathMatchRange = [uuidRegex rangeOfFirstMatchInString:homePath
                                                                  options:0
                                                                    range:NSMakeRange(0, [homePath length])];
    
    return [homePath substringWithRange:homeUUIDPathMatchRange];
}


- (BOOL) needHandleFilePath:(NSString *)filePath
{
    BOOL flag = YES;
    
    if ([filePath rangeOfString:homeUUID].location != NSNotFound)
    {
        flag = NO;
    }
    
    return flag;
}

- (NSString *) handlingOpenURL:(NSString *)openURL
{
    DebugLog(@"handlingOpenURL is %@",openURL);
    
    NSString *targetLink = nil;
    
    if (openURL !=nil)
    {
        if ([openURL hasPrefix:@"file:"])
        {
            if ([self needHandleFilePath:openURL]) {
                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *documentsDirectory = [paths objectAtIndex:0];
                NSString *targetRootFolder = [NSString stringWithFormat:@"file://%@",documentsDirectory];
                
                targetRootFolder = [targetRootFolder stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
                
                NSString *localFilePath = [openURL substringFromIndex:6];
                
                targetLink = [NSString stringWithString:[targetRootFolder stringByAppendingPathComponent:localFilePath]];
            } else {
                targetLink = [NSString stringWithString:openURL];
            }
        }
        else if ([openURL hasPrefix:@"http:"])
        {
            targetLink = [NSString stringWithString:openURL];
        }
        else if ([openURL hasPrefix:@"https:"])
        {
            targetLink = [NSString stringWithString:openURL];
        }
        else
        {
            targetLink = [NSString stringWithFormat:@"%@%@",@"https://",openURL];
        }
    }
    
    return targetLink;
}

- (void)registerShake:(NSString *)eventJS {
    self.shakeEventJS = eventJS;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectedShake) name:@"CPDeviceShaken" object:nil];

}

- (void)unRegisterShake {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"CPDeviceShaken" object:nil];
}

- (void) detectedShake
{
    
    if(!self.shakeEventJS)
        return;
    
    
    SystemSoundID soundID;
    
    NSString *name = @"shake_sound_male";
    
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    
    AudioServicesPlaySystemSound(soundID);
    
    NSString *jsCall = [NSString stringWithFormat:@"%@();",self.shakeEventJS];
    
    DebugLog(@"jsCall %@",jsCall);
    
    [_webContentView stringByEvaluatingJavaScriptFromString:jsCall];
    
}


@end
